<template>
  <div class="ec-app-container">
    <!-- 查询条件 -->
    <div class="filter-container">
      <el-form label-width="90px">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="模块名称：" >
              <el-input v-model="listQuery.name" placeholder="模块名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="状态：" >
              <el-select v-model="listQuery.status" placeholder="用户状态" clearable>
                <el-option v-for="(item, index) in GLOBAL.status" :key="index" :label= "item" :value="index"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" class="text-center">
            <el-button type="primary" class="border-4C7FD7 color-4C7FD7" icon="el-icon-search" @click="searchList">查询</el-button>
            <el-button class="border-4C7FD7 color-4C7FD7" @click="resetSearch">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- table -->
    <div>
      <div class="mt-30">
        <el-button class="filter-item" type="primary" @click="showDialog('新增模块')">新增</el-button>
      </div>
      <div class="mt-20">
        <el-table
          v-loading="listLoading"
          :data="list"
          border
          fit
          highlight-current-row
          style="width: 100%;"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="55"/>
          <el-table-column label="操作" align="center" width="200">
            <template slot-scope="scope">
              <el-button v-if="scope.row.object.status == 1" type="text" size="mini" @click="releaseStatus(scope.row, 0, '启用模块')">启用</el-button>
              <el-button v-else type="text" size="mini" @click="releaseStatus(scope.row, 1, '停用模块')">停用</el-button>
              <el-button type="text" size="mini" @click="toPath('adsetting/' + scope.row.id)">设置</el-button>
              <el-button type="text" size="mini" @click="toPath(`adsetting/${scope.row.id}`)">查看</el-button>
              <el-button type="text" size="mini" @click="deleteDate(scope.row.id, '删除模块')">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column label="模块名称" prop="id" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.object.name }}</span>
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="id" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.object.status | releaseStatus }}</span>
            </template>
          </el-table-column>
          <el-table-column label="应用终端" prop="id" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.object.applicationTerminal }}</span>
            </template>
          </el-table-column>
          <el-table-column label="修改时间" prop="id" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.updateTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="修改用户" prop="id" align="center">
            <template slot-scope="scope">
              <span>暂时没有</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="searchList" />
    </div>
    <!-- 新增修改 -->
    <el-dialog :visible.sync="dialogFormVisible" title="新增模块" width="450px">
      <el-form ref="objectForm" :model="object" :rules="objectRules" label-width="110px">
        <el-row>
          <el-form-item label="模块名称：" prop="name">
            <el-input v-model="object.name"/>
          </el-form-item>
          <el-form-item label="应用终端：" prop="roleName">
            <el-select v-model="object.applicationTerminal" placeholder="所属范围" clearable>
              <el-option v-for="(item, index) in GLOBAL.scopeTypes" :key = "index" :label= "item" :value="item"/>
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="btnLoading" type="primary" @click="onSubmit(message)">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination、
import mixin from './rules/ad'
export default {
  name: 'Ad',
  components: {
    Pagination
  },
  mixins: [mixin],
  data() {
    return {
      listQuery: {
        level: 'fy_adSetting',
        pageSize: 10,
        pageNum: 1
      },
      object: {
        'name': '',
        'applicationTerminal': '',
        'status': 1,
        'level2': '',
        'level1': '',
        'level': 'fy_adSetting'
      }
    }
  },
  created() {
    // 初始化
    this.searchList()
  }
}
</script>

<style scoped>

</style>
